//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<COrthoView.cpp>
///	@path	~/src/graphics/common/
///	@date	2008/11/02
///	@desc	.

#include "config/config.h"

#include "graphics/IDevice.h"
#include "graphics/RenderContext.h"
#include "graphics/dx9/import_dx9.h"
#include "graphics/common/COrthoView.h"

namespace xeres {
	
	IMPL_IOBJECT_CLASS_DYNAMIC( COrthoView );

	// COrthoView
	COrthoView::COrthoView( void )
		: m_resX( 0 )
		, m_resY( 0 )
		, m_aspect( 1 )
		, m_width( 2 )
		, m_height( 2 )
		, m_near( 0.0f )
		, m_far( 10000.f )
	{
		m_projMatrix.identity();
		m_viewMatrix.identity();
	}
	// ~COrthoView
	COrthoView::~COrthoView( void )
	{
	}
	// Reset
	void COrthoView::Reset( RenderContext& rc )
	{
		m_resX = rc.ResX<float>();
		m_resY = rc.ResY<float>();
		m_aspect = m_resX / m_resY;

		dx9::D3DXMatrixOrthoLH( (D3DXMATRIXA16*)&m_projMatrix, m_width, m_height, m_near, m_far );
	}
	// GetTransform
	Matrix<float> COrthoView::GetTransform( void )
	{
		return m_viewMatrix;
	}
	// GetProjection
	Matrix<float> COrthoView::GetProjection( void )
	{
		return m_projMatrix;
	}
	// SetTransform
	void COrthoView::SetTransform( const Matrix<float>& mat )
	{
		m_projMatrix = mat;
	}
	// LookAt
	void COrthoView::LookAt( const Vector<float>& eye , const Vector<float>& dir , const Vector<float>& up )
	{
		dx9::D3DXMatrixLookAtLH( (D3DXMATRIX*)&m_viewMatrix, (D3DXVECTOR3*)&eye, (D3DXVECTOR3*)&dir, (D3DXVECTOR3*)&up );
	}
	// SetViewport
	void COrthoView::SetViewport( float width , float height , float near_clip , float far_clip )
	{
		m_width = width;
		m_height = height;
		m_near = near_clip;
		m_far = far_clip;
		dx9::D3DXMatrixOrthoLH( (D3DXMATRIXA16*)&m_projMatrix, m_width, m_height, m_near, m_far );
	}

	// GetNear
	float COrthoView::GetNear( void ) const
	{
		return m_near;
	}

	// SetNear
	void COrthoView::SetNear( float near_clip )
	{
		SetViewport( m_width , m_height , near_clip , m_far );
	}

	// GetFar
	float COrthoView::GetFar( void ) const
	{
		return m_far;
	}

	// SetFar
	void COrthoView::SetFar( float far_clip )
	{
		SetViewport( m_width , m_height , m_near , far_clip );
	}
} // namespace xeres
